package com.example.vlille2.recherche;

import java.util.List;

import android.app.Activity;
import android.location.Location;

import com.example.vlille2.accueil.StationsAdapter;
import com.example.vlille2.base.Station;

public class RechercheAdapter extends StationsAdapter {

	private int minVelos,minPlaces;
	private int rayon;
	private boolean besoinDeCB;

	public RechercheAdapter(Activity context, List<Station> objects,Location userLocation,int minVelos, int minPlaces,int rayon) {
		super(context,objects, userLocation);

		this.minPlaces = minPlaces;
		this.minVelos = minVelos;
		this.rayon = rayon;
		this.besoinDeCB = false;

		calculDistanceToUser();
		filtrerStations();
	}

	/* rafraichissement */
	public void setMinVelos(int min)
	{
		this.minVelos = min;
		filtrerStations();
	}

	public void setMinPlaces(int min)
	{
		this.minPlaces = min;
		filtrerStations();
	}

	public void setRayon(int rayon)
	{
		this.rayon = rayon;
		filtrerStations();
	}

	public void setBesoinDeCB(boolean besoinDeCB) {
		this.besoinDeCB = besoinDeCB;
		filtrerStations();
	}

	public void filtrerStations()
	{
		filtrerListe();
		notifyDataSetChanged();
	}

	@Override
	protected void filtrerListe() {
		listeFiltree.clear();
		for(Station uneStation : liste)
		{
			if(uneStation.getVelos()>=minVelos
					&& uneStation.getPlaces()>=minPlaces
					&& uneStation.getDistanceUtilisateur()<=rayon
					&& (!besoinDeCB || uneStation.isCompatibleCB()))
				listeFiltree.add(uneStation);
		}
	}	
}
